import java.awt.Component;
import java.awt.event.MouseWheelEvent;
import java.awt.event.MouseWheelListener;
import javax.swing.JLayeredPane;

class MyJLayeredPane
extends JLayeredPane
implements MouseWheelListener
{
  private static final long serialVersionUID = 1L;

  MyJLayeredPane()
  {
    System.out.println("MyJLayeredPane()");
    setName("MyLayeredPane");
    add(new MyJPanel("/img/0101l.jpg",  10,  10), JLayeredPane.DEFAULT_LAYER);
    add(new MyJPanel("/img/0102l.jpg",  20,  20), JLayeredPane.DEFAULT_LAYER);
    add(new MyJPanel("/img/0103l.jpg",  30,  30), JLayeredPane.DEFAULT_LAYER);
    add(new MyJPanel("/img/0104l.jpg",  40,  40), JLayeredPane.DEFAULT_LAYER);
    add(new MyJPanel("/img/0105l.jpg",  50,  50), JLayeredPane.DEFAULT_LAYER);
    add(new MyJPanel("/img/0106l.jpg",  60,  60), JLayeredPane.DEFAULT_LAYER);
    add(new MyJPanel("/img/0107l.jpg",  70,  70), JLayeredPane.DEFAULT_LAYER);
    add(new MyJPanel("/img/0108l.jpg",  80,  80), JLayeredPane.DEFAULT_LAYER);
    add(new MyJPanel("/img/0109l.jpg",  90,  90), JLayeredPane.DEFAULT_LAYER);
    add(new MyJPanel("/img/0110l.jpg", 100, 100), JLayeredPane.DEFAULT_LAYER);
    add(new MyJPanel("/img/0111l.jpg", 110, 110), JLayeredPane.DEFAULT_LAYER);
    add(new MyJPanel("/img/0112l.jpg", 120, 120), JLayeredPane.DEFAULT_LAYER);
    add(new MyJPanel("/img/0113l.jpg", 130, 130), JLayeredPane.DEFAULT_LAYER);
    add(new MyJPanel("/img/0114l.jpg", 140, 140), JLayeredPane.DEFAULT_LAYER);
    add(new MyJPanel("/img/0115l.jpg", 150, 150), JLayeredPane.DEFAULT_LAYER);
    addMouseWheelListener(this);
  }

  public void mouseWheelMoved(MouseWheelEvent mwe)
  {
    System.out.println("MyLayeredPane.mouseWheelMoved("+mwe+")");
    int rotation = mwe.getWheelRotation();
    int top = getComponentCountInLayer(JLayeredPane.DEFAULT_LAYER);
    Component[] component = getComponentsInLayer(JLayeredPane.DEFAULT_LAYER);
    if (rotation > 0)
    {
      moveToBack(component[0]);
    }
    else
    {
      moveToFront(component[top-1]);
    }
  }
}
